package com.lineage.server.clientpackets;

import com.lineage.echo.ClientExecutor;
import com.lineage.server.datatables.lock.ClanReading;
import com.lineage.server.datatables.sql.ClanTable;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Clan;
import com.lineage.server.serverpackets.S_PacketBox;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C_PledgeContent extends ClientBasePacket {
  private static final Log _log = LogFactory.getLog(C_PledgeContent.class);
  
  public void start(byte[] decrypt, ClientExecutor client) {
    try {
      read(decrypt);
      L1PcInstance pc = client.getActiveChar();
      if (pc == null)
        return; 
      int clan_id = pc.getClanid();
      if (clan_id == 0)
        return; 
      int data = readC();
      if (data == 15) {
        String announce = readS();
        L1Clan clan = ClanReading.get().getTemplate(clan_id);
        clan.setAnnouncement(announce);
        ClanTable.getInstance().updateClan(clan);
        pc.sendPackets((ServerBasePacket)new S_PacketBox(168, announce));
      } else if (data == 16) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("目前不开放玩家修改备注!!"));
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } finally {
      over();
    } 
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
